﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demos.DesignPatterns._19_中介者模式
{
    /// <summary>
    /// 聊天室
    /// </summary>
    public class ChatRoom: IChatRoomMediator
    {
        private readonly List<MsgUser> _users = new();

        public void AddMsgUser(MsgUser user)
        {
            _users.Add(user);
        }

        public void SendMessage(string message, MsgUser sender)
        {
            foreach (var user in _users)
            {
                // 不给发送者发送消息
                if (user != sender)
                {
                    user.Receive(message);
                }
            }
        }
    }
}
